package com.mxchip.livestar.original.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;

import com.mxchip.livestar.utils.MyLog;
import com.mxchip.livestar.rx.RxBus;
import com.mxchip.livestar.rx.RxConstant;

public class UsbDiskReceiver extends BroadcastReceiver {
    public static int out_camera_idVendor = 0x2e7e, out_camera_idProduct = 0x204;

    //    public static int  out_camera_idVendor = 0x0c45, out_camera_idProduct = 0x6366;
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
            UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
            for (UsbDevice device : usbManager.getDeviceList().values()) {
                if (device.getVendorId() == out_camera_idVendor && device.getProductId() == out_camera_idProduct) {
//                    RxBus.get().post();
                }
            }
        } else if (action.equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
            UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
            for (UsbDevice device : usbManager.getDeviceList().values()) {
                if (device.getVendorId() == out_camera_idVendor && device.getProductId() == out_camera_idProduct) {
                    return;
                }
            }
            RxBus.get().post(RxConstant.OUT_CAMERA_NOTIFY, false);
        } else {
            MyLog.logD(MyLog.USB_DISK_RECEIVER_MODEL, "UsbDiskReceiver::" + "onReceive: " + action);
        }
    }
}
